﻿Imports System.Windows.Forms
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports Microsoft.Win32

Public Class AddItems
    Dim SQLResult As Object
    Dim Records_Retrieved As String = 0
    Dim conn As New SqlConnection(csb.ToString())

    Private Sub Btn_AddProj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_AddProj.Click
        Dim ProjName As String = InputBox("Enter Project Name", "Project Name")
        If ProjName = "" Then
            'Me.Close()
            GoTo Finish
        End If
        Try
            'Check if Duplicate - need to use dr. loop
            If ESBD_Form.ListItem_Exists("Project_TB", "PJ_Name", ProjName) = True Then
                MsgBox(ProjName + " already exists in the database." + vbCrLf + vbCrLf + "Please enter a different name and try again.", MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly)
            Else
                cmd.Connection = conn
                conn.Open()
                cmd.CommandText = "INSERT INTO Project_TB ( [PJ_Name] ) VALUES ('" + ProjName + "');"
                cmd.ExecuteScalar()
                MsgBox(ProjName + " has been added to the Project Name list.", MsgBoxStyle.Information)
                conn.Close()
            End If
        Catch ex As Exception
            MsgBox(ex.message + vbCrLf + vbCrLf + "Connection Failed")
            conn.Close()
            Me.Cursor = Cursors.Default
        End Try
Finish:
    End Sub

    Private Sub BTN_PCBManu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_PCBManu.Click
        'Dim conn As New SqlConnection(csb.ToString())
        Dim PCBManu As String = InputBox("Enter PCB Manufacturer Name", "PCB Manufacturer")
        If PCBManu = "" Then
            GoTo Finish
        End If
        Try
            If ESBD_Form.ListItem_Exists("PCBManu_TB", "Name", PCBManu) = True Then
                MsgBox(PCBManu + " already exists in the database." + vbCrLf + vbCrLf + "Please enter a different name and try again.", MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly)
            Else
                cmd.Connection = conn
                conn.Open()
                'Add item to list
                cmd.CommandText = "INSERT INTO PCBManu_TB ( [Name] ) VALUES ('" + PCBManu + "');"
                cmd.ExecuteScalar()
                MsgBox(PCBManu + " has been added to the PCB Manufacturer list.", MsgBoxStyle.Information)
                conn.Close()
            End If
        Catch ex As Exception
            MsgBox(ex.message + vbCrLf + vbCrLf + "Connection Failed")
            conn.Close()
            Me.Cursor = Cursors.Default
        End Try
Finish:

    End Sub

    Private Sub BTN_PCBAssembler_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_PCBAssembler.Click
        Dim PCBAssm As String = InputBox("Enter PCB Assembler Name", "PCB Assembler")
        If PCBAssm = "" Then
            GoTo Finish
        End If
        Try
            If ESBD_Form.ListItem_Exists("PCBAssm_TB", "Name", PCBAssm) = True Then
                MsgBox(PCBAssm + " already exists in the database." + vbCrLf + vbCrLf + "Please enter a different name and try again.", MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly)
            Else
                cmd.Connection = conn
                conn.Open()
                'Add item to list
                cmd.CommandText = "INSERT INTO PCBAssm_TB ( [Name] ) VALUES ('" + PCBAssm + "');"
                cmd.ExecuteScalar()
                MsgBox(PCBAssm + " has been added to the PCB Assembler list.", MsgBoxStyle.Information)
                conn.Close()
            End If
        Catch ex As Exception
            MsgBox(ex.message + vbCrLf + vbCrLf + "Connection Failed")
            conn.Close()
            Me.Cursor = Cursors.Default
        End Try
Finish:
    End Sub

    Private Sub Btn_AddCust_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_AddCust.Click
        Customer_Details.TB_Name.Text = ""
        Customer_Details.TB_Add1.Text = ""
        Customer_Details.TB_Add2.Text = ""
        Customer_Details.TB_City.Text = ""
        Customer_Details.TB_Country.Text = ""
        Customer_Details.TB_Notes.Text = ""
        Customer_Details.TB_State.Text = ""
        Customer_Details.TB_Zip.Text = ""

        Customer_Details.TB_Name.Select()
        Customer_Details.ShowDialog()

        If Customer_Details.DialogResult = System.Windows.Forms.DialogResult.Cancel Then
            GoTo Finish
        End If
Finish:
    End Sub

    Private Sub BTN_Status_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_Status.Click
        Dim Proj_Status As String = InputBox("Enter a New Status", "Status")
        If Proj_Status = "" Then
            GoTo Finish
        End If
        Try
            If ESBD_Form.ListItem_Exists("Status_TB", "Name", Proj_Status) = True Then
                MsgBox(Proj_Status + " already exists in the database." + vbCrLf + vbCrLf + "Please enter a different name and try again.", MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly)
            Else
                cmd.Connection = conn
                conn.Open()
                'Add item to list
                cmd.CommandText = "INSERT INTO Status_TB ( [Name] ) VALUES ('" + Proj_Status + "');"
                cmd.ExecuteScalar()
                MsgBox(Proj_Status + " has been added to the Status list.", MsgBoxStyle.Information)
                conn.Close()
            End If
        Catch ex As Exception
            MsgBox(ex.message + vbCrLf + vbCrLf + "Connection Failed")
            conn.Close()
            Me.Cursor = Cursors.Default
        End Try
Finish:
    End Sub

    Private Sub BTN_BuildType_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_BuildType.Click
        Dim BT As String = InputBox("Enter a New Build Type", "Build Type")
        If BT = "" Then
            GoTo Finish
        End If
        Try
            If ESBD_Form.ListItem_Exists("BuildType_TB", "Type", BT) = True Then
                MsgBox(BT + " already exists in the database." + vbCrLf + vbCrLf + "Please enter a different name and try again.", MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly)
            Else
                cmd.Connection = conn
                conn.Open()
                'Add item to list
                cmd.CommandText = "INSERT INTO BuildType_TB ( [Type] ) VALUES ('" + BT + "');"
                cmd.ExecuteScalar()
                MsgBox(BT + " has been added to the Build Type list.", MsgBoxStyle.Information)
                conn.Close()
            End If
        Catch ex As Exception
            MsgBox(ex.message + vbCrLf + vbCrLf + "Connection Failed")
            conn.Close()
            Me.Cursor = Cursors.Default
        End Try
Finish:
    End Sub
End Class
